<template>
  <div style="height:100%;width:100%;position:relative;">
    <div class="pagetop">
      <div style="width:100%;">
        <el-col>
          <div ref="buttondiv">
            <vxe-toolbar>
              <template v-slot:buttons>
                <table>
                  <tr>
                    <td>报告单元</td>
                    <td>
                      <rm-ddl-rptunit prgno="LIS131" v-model="rptunit" @change="unitchange" :appendtobody="true"
                        width="200px" :defaultflag="'1'" :clearable="false"></rm-ddl-rptunit>
                    </td>
                    <td :width="buttonwidth"></td>
                    <td>
                      <el-button @click="AddRecord()" icon="el-icon-plus" v-show="buttonvisible">新增</el-button>
                    </td>
                    <td>
                      <el-button @click="DelRecord()" icon="el-icon-delete" v-show="buttonvisible">删除</el-button>
                    </td>
                    <td>
                      <el-button @click="SaveAllRecord()" icon="el-icon-files">保存</el-button>
                    </td>
                  </tr>
                </table>
              </template>
            </vxe-toolbar>
          </div>
        </el-col>
      </div>

    </div>
    <div class="pagecenter">
      <el-tabs style="height:100%;" type="border-card" @tab-click="handleTabClick">
        <el-tab-pane label="分单类别">
          <rm-layout-right splitcolor="#ffffff" :splitwidth="3" :fixsize="800" :minfixsize="200">
            <div style="height:100%">
              <vxe-table :data.sync="tableDataGroupvs" @cell-dblclick="cellDBLClickEvent" @edit-closed="SeqClose"
                :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }" :loading="loading" height="auto"
                highlight-current-row highlight-hover-row resizable border header-align="center" show-overflow="tooltip"
                show-header-overflow="tooltip" size="mini" stripe column-width="100px" ref="tableGroupvs">
                <vxe-table-column key="req_groupname" field="req_groupname" title="对应分单类别"
                  width="200px"></vxe-table-column>
                <vxe-table-column key="seq" field="seq" title="序号" :edit-render="{ name: 'input' }" width="80px"
                  align="center"></vxe-table-column>
                <vxe-table-column key="reg_groupid" field="reg_groupid" title="对照ID" width="80px" align="right"
                  header-align="center"></vxe-table-column>
              </vxe-table>
            </div>
            <template v-slot:fix>
              <div style="height:100%">
                <vxe-table :data.sync="tableDataGroup" @cell-dblclick="cellDBLClickEvent" :loading="loadingDict"
                  height="auto" highlight-current-row highlight-hover-row resizable show-overflow="tooltip"
                  show-header-overflow="tooltip" size="mini" border stripe header-align="center" column-width="100px"
                  ref="tableGroup">
                  <vxe-table-column key="Inuse" field="Inuse" title="使用" width="40px" align="center">
                    <template v-slot="{ row }">
                      <el-checkbox v-model="row.Inuse" disabled false-label="0" true-label="1"></el-checkbox>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column key="req_groupcode" field="req_groupcode" title="分单类别代码"
                    width="100px"></vxe-table-column>
                  <vxe-table-column key="req_groupname" field="req_groupname" title="分单类别名称"
                    width="120px"></vxe-table-column>
                  <vxe-table-column key="tube_color" field="tube_color" title="试管颜色" width="80px">
                    <template v-slot="{ row }">
                      <div v-bind:style="{ background: '#' + ColorChange(row.tube_color) }" style="height:20px"></div>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column key="barcode_head" field="barcode_head" title="条码前缀" width="80px"></vxe-table-column>
                  <vxe-table-column key="collect_tips" field="collect_tips" title="采样提示" width="80px"></vxe-table-column>
                  <vxe-table-column key="labgroupname" field="labgroupname" title="所属组" width="60px"></vxe-table-column>
                  <vxe-table-column key="specimen_name" field="specimen_name" title="默认采集标本"
                    width="80px"></vxe-table-column>
                  <vxe-table-column key="description" field="description" title="备注" width="200px"></vxe-table-column>
                </vxe-table>
              </div>
            </template>
          </rm-layout-right>
        </el-tab-pane>
        <el-tab-pane label="输入模板">
          <rm-layout-right splitcolor="#ffffff" :splitwidth="3" :fixsize="600" :minfixsize="200" ref="layoutright">
            <div style="height: 100%">
              <vxe-table :data.sync="tableDataUnitMdl" @cell-dblclick="cellDBLClickEvent" @edit-closed="SeqClose"
                :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }" :loading="loading" height="auto"
                highlight-current-row highlight-hover-row resizable show-overflow="tooltip" show-header-overflow="tooltip"
                header-align="center" size="mini" border stripe column-width="100px" ref="tableUnitMdl">
                <vxe-table-column key="mdlname" field="mdlname" title="对应批次输入模板" width="160px"></vxe-table-column>
                <vxe-table-column key="autoinputflag" field="autoinputflag" title="自动输入" width="60px" align="center">
                  <template v-slot="{ row, rowIndex }">
                    <el-checkbox v-model="row.autoinputflag"></el-checkbox>
                  </template>
                </vxe-table-column>
                <vxe-table-column key="sampleno1" field="sampleno1" title="起始样本号"
                  :edit-render="{ name: 'input', autoselect: true }" width="80px" align="center"></vxe-table-column>
                <vxe-table-column key="sampleno2" field="sampleno2" title="结束样本号"
                  :edit-render="{ name: 'input', autoselect: true }" width="80px" align="center"></vxe-table-column>
                <vxe-table-column key="hotkey" field="hotkey" title="快捷键" :edit-render="{ name: 'input' }"
                  width="80px"></vxe-table-column>
                <vxe-table-column key="seq" field="seq" title="序号" :edit-render="{ name: 'input', autoselect: true }"
                  width="60px" align="center"></vxe-table-column>
                <vxe-table-column key="mdlspecimenname" field="mdlspecimenname" title="标本类型" width="80px"
                  align="center"></vxe-table-column>
                <vxe-table-column key="mdlinvalidflag" field="mdlinvalidflag" title="停用" width="40px" align="center">
                  <template v-slot="{ row, rowIndex }">
                    <el-checkbox v-model="row.mdlinvalidflag" disabled></el-checkbox>
                  </template>
                </vxe-table-column>
                <vxe-table-column key="inputmdlid" field="inputmdlid" title="对照ID" width="80px" align="right"
                  header-align="center"></vxe-table-column>
              </vxe-table>
            </div>
            <template v-slot:fix>
              <div style="height: 100%">
                <div style="height:calc(60% - 42px)">
                  <table>
                    <tr>
                      <td>快速搜索</td>
                      <td>
                        <el-input style="width:400px" v-model="searchmdl"></el-input>
                      </td>
                    </tr>
                  </table>
                  <vxe-table :data="mdllist" @cell-dblclick="cellDBLClickEvent" height="auto" highlight-current-row
                    @current-change="currentChangeEvent" :loading="loadingDict" highlight-hover-row resizable
                    show-overflow="tooltip" show-header-overflow="tooltip" border size="mini" stripe header-align="center"
                    column-width="100px" ref="tableMdl">
                    <vxe-table-column key="itemclassname" field="itemclassname" title="所属项目类别" width="80px"
                      align="center"></vxe-table-column>
                    <vxe-table-column key="mdlname" field="mdlname" title="模板名称" width="180px"></vxe-table-column>
                    <vxe-table-column v-if="IsAreaMode" key="belong_hospitalname" field="belong_hospitalname" title="所属医院"
                      width="120px" align="left"></vxe-table-column>
                    <vxe-table-column key="specimen_name" field="specimen_name" title="标本类型" width="80px"
                      align="center"></vxe-table-column>
                    <vxe-table-column key="inputcode" field="inputcode" title="输入码" width="80px"></vxe-table-column>
                    <vxe-table-column key="description" field="description" title="描述" width="80px"></vxe-table-column>
                    <vxe-table-column key="invalid" field="invalid" title="停用标志" width="80px" align="center">
                      <template v-slot="{ row }">
                        <el-checkbox v-model="row.valid" false-label="0" true-label="1" disabled></el-checkbox>
                      </template>
                    </vxe-table-column>
                    <vxe-table-column key="vsrptunitcnt" field="vsrptunitcnt" title="对照报告单元数" width="80px" align="right"
                      header-align="center"></vxe-table-column>
                    <vxe-table-column key="inputmdlid" field="inputmdlid" title="批输入模板ID" width="80px"></vxe-table-column>
                    <vxe-table-column key="labgroupname" field="labgroupname" title="工作组" width="80px"
                      align="center"></vxe-table-column>
                  </vxe-table>
                </div>
                <div style="height:40%;margin-top:42px">
                  <vxe-table :data.sync="tableDataContain" column-width="100px" height="auto" :loading="loadingDict"
                    highlight-current-row highlight-hover-row resizable border header-align="center"
                    show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                    <vxe-table-column :field="items.field" :key="items.field" :title="items.title" width="120px"
                      v-for="items in tableColumnCotain"></vxe-table-column>
                  </vxe-table>
                </div>
              </div>
            </template>
          </rm-layout-right>
        </el-tab-pane>
        <el-tab-pane label="申请项目">
          <rm-layout-right splitcolor="#ffffff" :splitwidth="3" :fixsize="700" :minfixsize="200" ref="layoutright">
            <div style="height:100%">
              <div v-show="Options.rptunitvsallhospreqitem == '1'">
                <table style="height:60px">
                  <tr>
                    <td style="width:60px">
                      <span style="font-size:12px">选择医院:</span>
                    </td>
                    <td>
                      <rm-ddl-common datatype="hospital" dataname="医院" v-model="hospcode" width="250px" isadmincanall="2"
                        @change="hospChange" :clearable="false"></rm-ddl-common>
                    </td>
                  </tr>
                </table>
              </div>
              <div style="height:65px">
                <table>
                  <tr>
                    <td>周几检验</td>
                    <td width="150px">
                      <el-input v-model="rptunitweekdays" placeholder="请输入周几检验" clearable=""></el-input>
                    </td>
                    <td>当日截止时间</td>
                    <td width="250px">
                      <el-input v-model="rptunitendtime" @focus="setrptunitendtime()" placeholder="请输入截止时间" clearable=""
                        :readonly="true"></el-input>
                    </td>

                  </tr>
                  <tr>
                    <td>搜索</td>
                    <td>
                      <vxe-input style="height:auto" v-model="leftsearchtext" type="search"></vxe-input>
                    </td>
                    <td colspan="2" style="text-align: center"><el-checkbox v-model="isnextorstop" false-label="0"
                        true-label="1">超过截止时间停止自动编号</el-checkbox></td>
                  </tr>
                </table>
              </div>
              <div
                :style="{ height: Options.rptunitvsallhospreqitem == '1' ? 'calc(100% - 100px)' : 'calc(100% - 65px)' }">
                <vxe-table :data.sync="Unitreqlist" @cell-dblclick="cellDBLClickEvent" @edit-closed="SeqClose"
                  :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }" :sort-config="{ trigger: 'cell' }"
                  :loading="loading" height="auto" border highlight-current-row highlight-hover-row resizable
                  show-overflow="tooltip" header-align="center" show-header-overflow="tooltip" size="mini" stripe
                  column-width="100px" ref="tableUnitreq">
                  <vxe-table-column key="req_item" field="req_item" title="申请项目" width="200px"></vxe-table-column>
                  <vxe-table-column key="defaultselectflag" field="defaultselectflag" title="默认" width="60px"
                    align="center">
                    <template v-slot="{ row, rowIndex }">
                      <el-checkbox v-model="row.defaultselectflag"></el-checkbox>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column key="inputcode" field="inputcode" title="快速输入码"
                    :edit-render="{ name: 'input', autoselect: true }" width="80px"></vxe-table-column>
                  <vxe-table-column key="sampleno1" field="sampleno1" title="起始样本号"
                    :edit-render="{ name: 'input', autoselect: true }" width="120px"></vxe-table-column>
                  <vxe-table-column key="sampleno2" field="sampleno2" title="结束样本号"
                    :edit-render="{ name: 'input', autoselect: true }" width="120px"></vxe-table-column>
                  <vxe-table-column key="sampleformat" field="sampleformat" title="样本号格式"
                    :edit-render="{ name: 'input', autoselect: true }" width="120px"></vxe-table-column>
                  <vxe-table-column key="seq" field="seq" title="序号" :edit-render="{ name: 'input', autoselect: true }"
                    width="80px"></vxe-table-column>
                  <vxe-table-column key="forbidinputflag" field="forbidinputflag" title="禁止手工输入" width="80px"
                    align="center">
                    <template v-slot="{ row, rowIndex }">
                      <el-checkbox v-model="row.forbidinputflag"></el-checkbox>
                    </template>
                  </vxe-table-column>
                  <!-- <vxe-table-column key="autonorulename" field="autonorulename" title="自动编号规则" width="80px">
                                      <template v-slot="{ row }">
                                          <el-select v-model="row.autonoruleid">
                                              <el-option :value="item.codeno" :label="item.codena" :key="item.codeno" v-for="item in OptionsAutorule"></el-option>
                                          </el-select>
                                      </template>
                                  </vxe-table-column> -->
                  <vxe-table-column key="rptunitid" field="rptunitid" title="报告单元ID" width="80px"></vxe-table-column>
                  <vxe-table-column key="weekdays" field="weekdays" title="周几检验" :edit-render="{ name: 'input' }"
                    width="80px"></vxe-table-column>
                  <vxe-table-column key="reqitemgroup" field="reqitemgroup" title="分组" width="50px">
                    <template v-slot="{ row }">
                      <el-select v-model="row.reqitemgroup">
                        <el-option value="A" label="A"></el-option>
                        <el-option value="B" label="B"></el-option>
                        <el-option value="C" label="C"></el-option>
                        <el-option value="D" label="D"></el-option>
                        <el-option value="E" label="E"></el-option>
                        <el-option value="F" label="F"></el-option>
                      </el-select>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column key="endtime" field="endtime" title="当日截止时间" :edit-render="{ name: 'input' }"
                    width="210px">
                    <template v-slot:edit="{ row }">
                      <el-input style="width:100%;" @focus="setendtime($event, row)" v-model="row.endtime"
                        placeholder="请输入截止时间" clearable="" :readonly="true"></el-input>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column key="specialreqitemflag" field="specialreqitemflag" title="特别关注" width="60px"
                    align="center">
                    <template v-slot="{ row, rowIndex }">
                      <el-checkbox v-model="row.specialreqitemflag"></el-checkbox>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column key="req_itemcode" field="req_itemcode" title="申请项目代码" width="100px"
                    sortable></vxe-table-column>
                </vxe-table>
              </div>
            </div>
            <template v-slot:fix>
              <div style="height:100%">
                <div style="height:65px">
                  <table>
                    <tr>
                      <td>查找</td>
                      <td>
                        <vxe-input style="height:auto" v-model="searchtext" type="search"></vxe-input>
                      </td>
                      <td>分单类别</td>
                      <td>
                        <rm-ddl-common datatype="reqgroup" dataname="分单类别" width="200px" v-model="reqgroupname"
                          @change="reqgroupchange"></rm-ddl-common>
                      </td>
                    </tr>
                    <tr>
                      <td></td>
                      <td>
                        <el-checkbox label="删除对照不提醒" v-model="deltipflag"></el-checkbox>
                      </td>
                      <td></td>
                      <td>
                        <el-checkbox label="禁止输入模式" v-model="forbidflag"></el-checkbox>
                      </td>
                    </tr>
                  </table>
                </div>
                <div style="height:calc(100% - 65px)">
                  <vxe-table :data.sync="list" @cell-dblclick="cellDBLClickEvent" :loading="loadingDict" height="auto"
                    highlight-current-row highlight-hover-row resizable show-overflow="tooltip" border
                    show-header-overflow="tooltip" size="mini" stripe header-align="center" column-width="100px"
                    ref="tablereq">
                    <vxe-table-column key="Inuse" field="Inuse" title="使用" width="40px" align="center">
                      <template v-slot="{ row, rowIndex }">
                        <el-checkbox v-model="row.Inuse" disabled false-label="0" true-label="1"></el-checkbox>
                      </template>
                    </vxe-table-column>
                    <vxe-table-column key="req_groupna" field="req_groupna" title="分单类别" width="100px"></vxe-table-column>
                    <vxe-table-column key="req_itemname" field="req_itemname" title="申请项目名称"
                      width="120px"></vxe-table-column>
                    <vxe-table-column key="item_price" field="item_price" title="价格" width="100px" align="right"
                      header-align="center"></vxe-table-column>
                    <vxe-table-column key="req_itemcode" field="req_itemcode" title="申请项目代码"
                      width="120px"></vxe-table-column>
                    <vxe-table-column key="his_itemcode" field="his_itemcode" title="HIS原始代码"
                      width="120px"></vxe-table-column>
                    <vxe-table-column key="inputcode" field="inputcode" title="助记符" width="120px"></vxe-table-column>
                  </vxe-table>
                </div>
              </div>
            </template>
          </rm-layout-right>

        </el-tab-pane>
        <el-tab-pane label="标本类型">
          <rm-layout-right splitcolor="#ffffff" :splitwidth="3" :fixsize="600" :minfixsize="200">
            <div style="height: 100%">
              <vxe-table :data.sync="tableDataUnitSpec" @cell-dblclick="cellDBLClickEvent" @edit-closed="SeqClose"
                :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }" :loading="loading" height="auto"
                highlight-current-row highlight-hover-row resizable show-overflow="tooltip" header-align="center" border
                show-header-overflow="tooltip" size="mini" stripe column-width="100px" ref="tableUnitspec">
                <vxe-table-column key="specimen_name" field="specimen_name" title="标本类型" width="200px"></vxe-table-column>
                <vxe-table-column key="seq" field="seq" title="序号" :edit-render="{ name: 'input', autoselect: true }"
                  width="100px" align="center"></vxe-table-column>
                <vxe-table-column key="specimen_code" field="specimen_code" title="标本类型代码"
                  width="100px"></vxe-table-column>
              </vxe-table>
            </div>
            <template v-slot:fix>
              <div style="height: 100%">
                <vxe-table :data.sync="tableDataSpec" @cell-dblclick="cellDBLClickEvent" :loading="loadingDict"
                  height="auto" highlight-current-row highlight-hover-row resizable show-overflow="tooltip"
                  show-header-overflow="tooltip" size="mini" border stripe header-align="center" column-width="100px"
                  ref="tablespec">
                  <vxe-table-column key="Inuse" field="Inuse" title="选择" width="40px" align="center">
                    <template v-slot="{ row, rowIndex }">
                      <el-checkbox v-model="row.Inuse" disabled false-label="0" true-label="1"></el-checkbox>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column key="specimen_code" field="specimen_code" title="标本类型代码"
                    width="160px"></vxe-table-column>
                  <vxe-table-column key="specimen_name" field="specimen_name" title="标本类型名称"
                    width="160px"></vxe-table-column>
                  <vxe-table-column key="inputcode" field="inputcode" title="拼音码" width="100px"></vxe-table-column>
                </vxe-table>
              </div>
            </template>
          </rm-layout-right>
        </el-tab-pane>
        <el-tab-pane label="报告备注">
          <rm-layout-right splitcolor="#ffffff" :splitwidth="3" :fixsize="600" :minfixsize="200">
            <div style="height: 100%">
              <vxe-table :data.sync="tableDataUnitComm" @cell-dblclick="cellDBLClickEvent" @edit-closed="SeqClose"
                :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }" :loading="loading" height="auto"
                highlight-current-row highlight-hover-row resizable show-overflow="tooltip" show-header-overflow="tooltip"
                header-align="center" size="mini" stripe border column-width="100px" ref="tableUnitComm">
                <vxe-table-column key="comments" field="comments" title="备注文字" width="200px"></vxe-table-column>
                <vxe-table-column key="seq" field="seq" title="序号" :edit-render="{ name: 'input' }"
                  width="100px"></vxe-table-column>
                <vxe-table-column key="inputcode" field="inputcode" title="输入码" :edit-render="{ name: 'input' }"
                  width="100px"></vxe-table-column>
              </vxe-table>
            </div>
            <template v-slot:fix>
              <div style="height: 100%">
                <div>
                  <table>
                    <tr>
                      <td>快速搜索</td>
                      <td>
                        <el-input style="width:400px" v-model="searchcomm"></el-input>
                      </td>
                    </tr>
                  </table>
                </div>
                <vxe-table :data.sync="commlist" @cell-dblclick="cellDBLClickEvent" :loading="loadingDict" height="auto"
                  highlight-current-row highlight-hover-row resizable show-overflow="tooltip"
                  show-header-overflow="tooltip" size="mini" stripe border header-align="center" column-width="100px"
                  ref="tableComm">
                  <vxe-table-column key="Inuse" field="Inuse" title="选择" width="40px" align="center">
                    <template v-slot="{ row, rowIndex }">
                      <el-checkbox v-model="row.Inuse" disabled false-label="0" true-label="1"></el-checkbox>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column key="codena" field="codena" title="常见备注" width="160px"></vxe-table-column>
                  <vxe-table-column key="inputcode" field="inputcode" title="录入码" width="120px"></vxe-table-column>
                  <vxe-table-column key="codeno" field="codeno" title="代码" width="120px"></vxe-table-column>
                </vxe-table>
              </div>
            </template>
          </rm-layout-right>
        </el-tab-pane>
        <el-tab-pane label="核收号段">
          <vxe-table :data.sync="tableDataSample" height="auto" @edit-closed="SeqClose" :keyboard-config="keyConfig"
            highlight-current-row highlight-hover-row resizable show-overflow="tooltip"
            :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }" :loading="loading" header-align="center"
            show-header-overflow="tooltip" size="mini" stripe border column-width="100px" ref="tableSample">
            <vxe-table-column key="seq" field="seq" title="序号" :edit-render="{ name: 'input', autoselect: true }"
              width="100px"></vxe-table-column>
            <vxe-table-column key="startno" field="startno" title="开始号" :edit-render="{ name: 'input', autoselect: true }"
              width="120px"></vxe-table-column>
            <vxe-table-column key="endno" field="endno" title="截止号" :edit-render="{ name: 'input', autoselect: true }"
              width="120px"></vxe-table-column>
            <vxe-table-column key="segname" field="segname" title="号段名称" :edit-render="{ name: 'input' }"
              width="160px"></vxe-table-column>
            <vxe-table-column key="pat_typename" field="pat_typename" title="适用病人类型" width="220px">
              <template v-slot="{ row, rowIndex }">
                <rm-ddl-common @change="pat_typechange($event, row)" datatype="seccode" kindno="PT" dataname="病人类型"
                  v-model="row.pat_typecode" width="200px"></rm-ddl-common>
              </template>
            </vxe-table-column>
            <vxe-table-column key="specimencode" field="specimencode" title="适用标本类型" width="220px">
              <template v-slot="{ row, rowIndex }">
                <rm-ddl-common @change="smp_specimenchange($event, row)" datatype="specimen" dataname="标本类型"
                  v-model="row.specimencode" width="200px"></rm-ddl-common>
              </template>
            </vxe-table-column>
          </vxe-table>
        </el-tab-pane>
        <el-tab-pane label="样本号跳转规则">
          <vxe-table :data.sync="tableDataSmpGoto" height="auto" highlight-current-row highlight-hover-row resizable
            show-overflow="tooltip" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }"
            :keyboard-config="keyConfig" :loading="loading" show-header-overflow="tooltip" size="mini" stripe border
            header-align="center" column-width="100px" ref="tableSmpgoto">
            <vxe-table-column key="currsmpno" field="currsmpno" title="当前样本号"
              :edit-render="{ name: 'input', autoselect: true }" width="120px"></vxe-table-column>
            <vxe-table-column key="nextsmpno" field="nextsmpno" title="下一个跳转到样本号"
              :edit-render="{ name: 'input', autoselect: true }" width="180px"></vxe-table-column>
          </vxe-table>
        </el-tab-pane>
        <el-tab-pane label="抗生素组" v-if="!isbis">
          <vxe-table :data.sync="tableDataMedgroup" :loading="loading" :keyboard-config="keyConfig"
            :keyboard-local-config="keyLocalConfig" height="auto" highlight-current-row highlight-hover-row resizable
            header-align="center" show-overflow="tooltip" show-header-overflow="tooltip" size="mini" stripe border
            column-width="100px" ref="tableMedgroup">
            <vxe-table-column key="medgroupname" field="medgroupname" title="抗生素组ID" width="220px">
              <template v-slot="{ row, rowIndex }">
                <rm-ddl-common @change="medgroupchange($event, row)" datatype="labmedgroup" dataname="抗生素组ID"
                  v-model="row.medgroupcode" width="200px"></rm-ddl-common>
              </template>
            </vxe-table-column>
            <vxe-table-column key="rptunitid" field="rptunitid" title="报告单元ID" width="120px"></vxe-table-column>
          </vxe-table>
        </el-tab-pane>
        <el-tab-pane label="申请科室">
          <vxe-table :data.sync="tableDataDept" :loading="loading" height="auto" :keyboard-config="keyConfig"
            :keyboard-local-config="keyLocalConfig" highlight-current-row highlight-hover-row resizable
            show-overflow="tooltip" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }"
            show-header-overflow="tooltip" size="mini" stripe border header-align="center" column-width="100px"
            ref="tableDept">
            <vxe-table-column key="seq" field="seq" title="序号" :edit-render="{ name: 'input' }"
              width="120px"></vxe-table-column>
            <vxe-table-column key="req_deptno" field="req_deptno" title="申请科室代码" width="220px">
              <template v-slot="{ row, rowIndex }">
                <rm-ddl-common @change="deptchange($event, row)" datatype="dept" dataname="科室" v-model="row.req_deptno"
                  width="200px"></rm-ddl-common>
              </template>
            </vxe-table-column>
          </vxe-table>
        </el-tab-pane>
        <el-tab-pane label="列表过滤条件">
          <rm-layout-right splitcolor="#ffffff" :splitwidth="3" :fixsize="450" :minfixsize="200">
            <div class="cond-table">
              <vxe-table ref="tableConditiond" :data.sync="tableDataCond" @current-change="currentChangeEventCon"
                height="auto" highlight-current-row resizable show-overflow="tooltip" show-header-overflow="tooltip"
                size="mini" border stripe header-align="center" column-width="100px">
                <!-- <vxe-table-column field="rptunitid" title="报告单元ID" width="120px"></vxe-table-column> -->
                <vxe-table-column field="condname" title="条件名称" width="120px"></vxe-table-column>
                <vxe-table-column field="condsql" title="条件SQL" width="400px"></vxe-table-column>
                <vxe-table-column field="useflag" title="在用标志" width="80px" align="center">
                  <template v-slot="{ row }">
                    <el-checkbox v-model="row.useflag" disabled true-label="1" false-label="0"></el-checkbox>
                  </template>
                </vxe-table-column>
                <vxe-table-column field="seq" title="序号" width="60px" align="center"></vxe-table-column>
              </vxe-table>
            </div>
            <template v-slot:fix>
              <table style="width: 100%">
                <tr>
                  <td>
                    条件名称
                  </td>
                  <td colspan="2">
                    <el-input v-model="addParam.condname" ref="input1" @keyup.enter.native="nextFocus(1)"
                      :disabled="editaddParamflag"></el-input>
                  </td>
                </tr>
                <tr>
                  <td>
                    序号
                  </td>
                  <td>
                    <el-input v-model="addParam.seq" ref="input2" @keyup.enter.native="nextFocus(2)"
                      :disabled="editaddParamflag"></el-input>
                  </td>
                  <td>
                    <el-checkbox v-model="addParam.useflag" true-label="1" false-label="0"
                      :disabled="editaddParamflag"></el-checkbox> 在用标志
                  </td>
                </tr>
                <tr>
                  <td>
                    条件SQL
                  </td>
                  <td colspan="2">
                    <el-input class="sql-text" type="textarea" v-model="addParam.condsql" ref="input3"
                      :disabled="editaddParamflag" @dblclick.native="opendialog" placeholder="双击打开列表过滤条件向导"></el-input>
                  </td>
                </tr>
                <tr>
                  <td style="vertical-align: top;height:100%">
                    条件名称
                  </td>
                  <td colspan="2">
                    <el-input v-model="addParam.condname" ref="input1" @keyup.enter.native="nextFocus(1)"
                      :disabled="editaddParamflag"></el-input>
                  </td>
                </tr>
              </table>
              <!-- <div class="cond-edit">
                               <div class="edit-row">
                                  <div class="edit-row-title">报告单元ID</div>
                                  <div class="edit-row-text">
                                      <el-input v-model="addParam.rptunitid" disabled></el-input>
                                  </div>
                              </div>
                              <div class="edit-row">
                                  <div class="edit-row-title">条件名称</div>
                                  <div class="edit-row-text">

                                  </div>
                              </div>
                              <div class="edit-row">
                                  <div class="edit-row-title">序号</div>
                                  <div style="width: 80px">

                                  </div>
                                  <div style="width: 200px;text-align: right;">

                                  </div>
                              </div>
                              <div class="edit-row">
                                  <div class="edit-row-title">条件SQL</div>
                                  <div class="edit-row-text">

                                  </div>
                              </div>
                          </div> -->
            </template>
          </rm-layout-right>
          <!-- <div class="cond-content">


                  </div> -->
        </el-tab-pane>
        <el-tab-pane label="报告标记">
          <vxe-table :data.sync="tableDataMark" height="auto" :keyboard-config="keyConfig" highlight-current-row
            highlight-hover-row resizable show-overflow="tooltip"
            :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }" :loading="loading" header-align="center"
            show-header-overflow="tooltip" size="mini" stripe border column-width="100px" ref="tableMark">
            <vxe-table-column key="markno" field="markno" title="标记代码" :edit-render="{ name: 'input', autoselect: true }"
              width="120px">
              <template v-slot="{ row }">
                <rm-ddl-common datatype="reportmark" v-model="row.markno"
                  @change="MarkChange(arguments, row)"></rm-ddl-common>
              </template>
            </vxe-table-column>
            <vxe-table-column key="markname" field="markname" title="标记说明" width="160px"></vxe-table-column>
            <vxe-table-column key="seq" field="seq" title="序号" :edit-render="{ name: 'input' }"
              width="100px"></vxe-table-column>
          </vxe-table>
        </el-tab-pane>
      </el-tabs>
    </div>
    <el-dialog v-el-drag-dialog :close-on-click-modal="false" :title="dialogtitle" :visible.sync="dialogFormVisible"
      width="500px">
      <div class="el-message-box__status el-icon-warning"></div>
      <div class="el-message-box__message">
        <p>您是否要删除当前申请项目和报告单元的对照关系?</p>
      </div>
      <div style="text-align:right">
        <span class="dialog-footer" slot="footer">
          <el-button @click="UnitReqdblEvent(), dialogFormVisible = false">确 定</el-button>
          <el-button @click="dialogFormVisible = false">取 消</el-button>
        </span>
      </div>
    </el-dialog>

    <el-dialog v-el-drag-dialog :close-on-click-modal="false" :title="dialogmdltitle" :visible.sync="dialogmdlVisible"
      width="650px">
      <div style="text-align:right">
        <div style="text-align:left"><span>{{ mdlunititem }}</span></div>
        <span class="dialog-footer" slot="footer">
          <el-button @click="dialogmdlVisible = false, UnitmdlReqAdd(), UnitmdlAdd()">确 定</el-button>
          <el-button @click="dialogmdlVisible = false, UnitmdlAdd()">取 消</el-button>
        </span>
      </div>
    </el-dialog>

    <el-dialog v-el-drag-dialog :close-on-click-modal="false" title="设置截止时间" :visible.sync="endtimedialogForm"
      width="350px" height="200px">
      <el-form :inline="true" @submit.native.prevent label-width="auto" ref="form1" style="border: 1px solid #ccc">
        <table>
          <tr>
            <td>工作日截止时间</td>
            <td>
              <el-time-picker v-model="workday_endtime" placeholder="任意时间点" value-format="HH:mm" format="HH:mm"
                style="width:100%"></el-time-picker>
            </td>
          </tr>
          <tr>
            <td>周末截止时间</td>
            <td>
              <el-time-picker v-model="weekend_endtime" placeholder="任意时间点" value-format="HH:mm" format="HH:mm"
                style="width:100%"></el-time-picker>
            </td>
          </tr>
          <tr>
            <td>节假日截止时间</td>
            <td>
              <el-time-picker v-model="holiday_endtime" placeholder="任意时间点" value-format="HH:mm" format="HH:mm"
                style="width:100%"></el-time-picker>
            </td>
          </tr>
        </table>
      </el-form>
      <div style="text-align: right; padding-top: 5px">
        <el-button type="primary" @click="CommitEndtime()">确定</el-button>
        <el-button @click="endtimedialogForm = false">取消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="列表过滤条件向导" v-el-drag-dialog :close-on-click-modal="false" :visible.sync="outerVisible" height="500px"
      width="780px">
      <el-dialog :append-to-body="true" :close-on-click-modal="false" :title="outerdialogtitle"
        :before-close="cancelinnerdialog" :visible.sync="dialogTableVisible" v-if="dialogx">
        <rm-pop-common @change="popcomchange" @cancel="cancelinnerdialog" :datatype="dataclass"></rm-pop-common>
      </el-dialog>
      <el-form>
        <el-row>
          <div style="width: 100%; float: left">
            <el-input type="textarea" :rows="5" v-model="dialogdata" id="topdiv"></el-input>
          </div>
        </el-row>
        <el-row>
          <div style="height: 440px; border: 1px solid #ccc; margin-top: 5px">
            <div style="float:left; left: 5px; width:550px; height:100%;">
              <div style="width: 100%; float: left; height: 40px">
                <div style="width: 60%; float: left">
                  <el-form>
                    <el-form-item label="字段快速查找" label-width="120">
                      <el-input v-model="quicklysearch" style="width: 200px" placeholder="代码、名称、所属表"
                        @keyup.enter.native="PopListSearch"></el-input>
                    </el-form-item>
                  </el-form>
                </div>
                <div style="width: 40%; float: left; margin-top: 5px">
                  <el-button @click="TestSql" icon="el-icon-save">测试sql</el-button>
                  <el-button @click="savedialog" icon="el-icon-document">确 定</el-button>
                  <el-button @click="outerVisible = false" :autofocus="true" icon="el-icon-close">取 消</el-button>
                </div>
              </div>
              <div style="width: 100%; float: left; height: 390px">
                <vxe-table show-overflow ref="xTable2" height="auto" row-id="id" :select-config="{ reserve: true }"
                  :data.sync="poptableData" show-header-overflow highlight-current-row highlight-hover-row resizable
                  border @cell-click="popcurrentChangeEvent" size="mini">
                  <vxe-table-column type="index" title="NO." width="40"></vxe-table-column>
                  <vxe-table-column field="col_table" title="字段所属表" width="100" sortable
                    header-align="center"></vxe-table-column>
                  <vxe-table-column field="col_code" title="字段代码" width="130" sortable
                    header-align="center"></vxe-table-column>
                  <vxe-table-column field="col_name" title="字段名称" width="140" sortable
                    header-align="center"></vxe-table-column>
                  <vxe-table-column field="hasvaluelist" title="有无取值列表" width="120" sortable header-align="center">
                    <template v-slot="{ row }">
                      <el-button v-if="row.hasvaluelist" style="width: 100px; margin: 4px"
                        @click.native="SelectColVal(row.col_code, row.col_name)">{{ row.hasvaluelist }}</el-button>
                    </template>
                  </vxe-table-column>
                </vxe-table>
              </div>
            </div>
            <div style="float:left; width: 200px;">
              <div style="text-align: center; position: realative">
                <table style="text-align: center">
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('+')">+</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('-')">-</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('*')">*</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('/')">/</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('>')">&gt;</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('>=')">&gt;=</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('<')">&lt;</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('<=')"> &lt;=</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('(')">(</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate(')')">)</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('and')">AND</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('or')"> OR</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('=')">等于</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('<>')">不等于</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('not')">not</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('in')">in</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('like')">like</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('%')">%</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" style="text-align: left;">
                      <span style="color:blue;">*单击左侧列表即可把该字段加入sql中，</span>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" style="text-align: left;">
                      <span style="color:blue;">点击按钮可选择该字段对应的值。</span>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="openExample()">示例</el-button>
                    </td>
                  </tr>
                </table>
              </div>
            </div>
          </div>
        </el-row>
      </el-form>
    </el-dialog>
    <el-dialog title="示例" v-el-drag-dialog :close-on-click-modal="false" :visible.sync="exampleVisible" width="780px">
      <div style="width: 18%; float: left; height: 500px; margin-bottom: 4px;">
        <vxe-table show-overflow height="auto" row-id="id" :select-config="{ reserve: true }"
          :data.sync="tableDataExample" show-header-overflow highlight-current-row highlight-hover-row resizable border
          @cell-click="exampleValChangeEvent" v-model="dialogdata" size="mini">
          <vxe-table-column field="condition_name" title="条件名称" width="130" sortable
            header-align="center"></vxe-table-column>
          <vxe-table-column field="condition_value" title="条件值" width="100" sortable header-align="center"
            v-if="false"></vxe-table-column>
        </vxe-table>
      </div>
      <div style="width: 80%; float: left; height: 500px; margin-left: 4px;margin-bottom: 4px;padding: 4px 4px 4px 4px;">
        {{ exampledata }}
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import { request } from "http";
import XE from "xe-utils";
export default {
  name: "LIS131",
  data() {
    return {
      loading: false,
      loadingDict: false,

      IsAreaMode: false,

      workday_endtime: "",
      weekend_endtime: "",
      holiday_endtime: "",
      endtimedialogForm: false,
      endtime_row: {},
      endtime_code: {},

      rptunit: "",
      buttonwidth: "",
      searchtext: "",
      leftsearchtext: "",
      searchmdl: "",
      searchcomm: "",
      deltipflag: false,
      forbidflag: false,
      reqgroupname: "",
      reqgroup: 0,
      dialogtitle: "提示",
      dialogmdltitle: "有以下报告项目没有对应的报告单元,是否立即对照?",
      dialogFormVisible: false,
      dialogmdlVisible: false,
      buttonvisible: false,
      mdlunititem: "",
      mdlFirst: true,
      reqFirst: true,
      specFirst: true,
      commFirst: true,
      sampleFirst: true,
      smpgotoFirst: true,
      medgroupFirst: true,
      deptFirst: true,
      condFirst: true,
      MarkFirst: true,
      seqChangeflag: false,
      mdlid: 0,

      tableDataGroupvs: [],
      tableDataGroupvsIndex: [],
      tableDataGroup: [],
      tableDataCond: [],
      addParam: {},
      editaddParamflag: true,
      tableDataUnitMdl: [],
      tableDataMdl: [],
      tableDataMdlTemp: [],
      tableDataUnitreq: [],
      tableDatareq: [],
      OptionsAutorule: [],
      tableDatareqTemp: [],
      tableDataUnitSpec: [],
      tableDataSpec: [],
      tableDataSpecTemp: [],
      tableDataUnitComm: [],
      tableDataComm: [],
      tableDataCommTemp: [],
      tableDataSample: [],
      tableDataSmpGoto: [],
      tableDataMedgroup: [],
      tableDataDept: [],
      tableDataContain: [],
      tableColumnCotain: [],
      tableDataMark: [],
      TabLabel: "分单类别",
      Options: [], //配置
      hospcode: this.$tool.getSession(this.$tool.selectedhis),
      keyConfig: {
        isDel: true,
        isTab: true,
        isEdit: true
      },
      keyLocalConfig: {
        isArrow: true
      },
      isbis: false,
      rptunitweekdays: "",
      rptunitendtime: "",
      isnextorstop: "0",
      rptunitendtimeuseflag: false,
      outerVisible: false,
      outerdialogtitle: "",
      dialogTableVisible: false,
      dialogx: false,
      dataclass: "",
      dialogdata: "",
      quicklysearch: "",
      poptableData: [],
      poptempData: [],
      exampledata: "",
      exampleVisible: false,
      tableDataExample: [
        {
          condition_name: "加急门诊",
          condition_value: "a.pat_typecode='3' and a.emer_flag = '1'",
        },
        {
          condition_name: "糖耐量合并后",
          condition_value: "exists (select 1 from req_detail z1 where z1.barcode = a.barcode and z1.req_itemcode in ('LIS01690'))",
        },
        {
          condition_name: "糖耐量全部",
          condition_value: "exists (select 1 from req_detail z1 where z1.barcode = a.barcode and z1.req_itemcode in ('LIS01690','LIS01693','LIS01694','LIS01695'))",
        },
      ],
    };
  },
  computed: {
    list() {
      let filterName = this.searchtext.trim();
      var filterClass = this.req_groupname;
      if (filterName || filterClass) {
        let filterRE = new RegExp(filterName, "gi");
        let searchProps = ["req_groupna", "req_itemname", "req_itemcode", "his_itemcode", "inputcode"];
        let rest = this.tableDatareq.filter(item => {
          return item.req_itemname.indexOf(filterName) > -1 || (item.req_groupna ? item.req_groupna.indexOf(filterName) > -1 : false) || (item.req_itemcode ? item.req_itemcode.indexOf(filterName) > -1 : false) || (item.his_itemcode ? item.his_itemcode.indexOf(filterName) > -1 : false) || (item.inputcode ? item.inputcode.indexOf(filterName) > -1 : false);
        });
        return rest;
      } else {
        return this.tableDatareq;
      }
    },
    mdllist() {
      let filterName = this.searchmdl.trim();
      if (filterName) {
        let filterRE = new RegExp(filterName, "gi");
        let searchProps = ["itemclassname", "mdlname", "specimen_name", "inputcode", "description", "vsrptunitcnt", "inputmdlid", "labgroupname"];
        let rest = this.tableDataMdl.filter(item => {
          return (item.itemclassname ? item.itemclassname.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.mdlname ? item.mdlname.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.specimen_name.toUpperCase() ? item.specimen_name.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.inputcode ? item.inputcode.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.description ? item.description.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.vsrptunitcnt ? item.vsrptunitcnt.indexOf(filterName) > -1 : false) || (item.inputmdlid ? item.inputmdlid.indexOf(filterName) > -1 : false) || (item.labgroupname ? item.labgroupname.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false);
        });
        return rest;
      } else {
        return this.tableDataMdl;
      }
    },
    commlist() {
      let filterName = this.searchcomm.trim();
      if (filterName) {
        let filterRE = new RegExp(filterName, "gi");
        let searchProps = ["codena", "codeno", "inputcode"];
        let rest = this.tableDataComm.filter(item => {
          return (item.codena ? item.codena.indexOf(filterName) > -1 : false) || (item.codeno ? item.codeno.indexOf(filterName) > -1 : false) || (item.inputcode ? item.inputcode.indexOf(filterName) > -1 : false);
        });
        return rest;
      } else {
        return this.tableDataComm;
      }
    },
    Unitreqlist() {
      let filterName = this.leftsearchtext.trim();
      if (filterName) {
        let filterRE = new RegExp(filterName, "gi");
        let searchProps = ["req_itemname", "req_itemcode"];
        let rest = this.tableDataUnitreq.filter(item => {
          return item.req_itemname.indexOf(filterName) > -1 || (item.req_itemcode ? item.req_itemcode.indexOf(filterName) > -1 : false);
        });
        return rest;
      } else {
        return this.tableDataUnitreq;
      }
    }
  },
  watch: {
    searchmdl(val) {
      var length = this.tableDataMdl.length;
      this.$nextTick(() => {
        var row = this.$refs.tableMdl.getCurrentRow();
        if (this.$refs.tableMdl.tableData.length > 0) row = this.$refs.tableMdl.tableData[0];
        if (row.inputmdlid) {
          this.$refs.tableMdl.setCurrentRow(row);
          this.LoadMdlDetail(row.inputmdlid);
        } else {
          this.LoadMdlDetail(0);
        }
      });
    }
  },
  created() {
    this.isbis = this.$tool.checkBis();
    this.InitOptions();
    this.LoadTable(1);
    this.SetIsAreaMode();
    //this.LoadTableDict(1);
  },
  mounted() { },
  updated() {
    this.getButtonWidth();
    var selectrow = {};
  },
  methods: {
    opendialog() {
      this.$tool
        .request({
          url: "LIS/LIS1/LIS131",
          method: "post",
          data: {
            action: "inittablecolumn"
          }
        })
        .then(res => {
          console.log('opendialog', res)
          this.poptableData = res.data;
          this.poptempData = XE.clone(res.data, true);
          this.dialogdata = this.addParam.condsql;
        });
      this.outerVisible = true;
    },
    openExample() {
      this.exampleVisible = true;
    },
    exampleValChangeEvent({ row, column }) {
      //示例弹窗行选中事件，显示对应值
      this.exampledata = row.condition_value;
    },
    cancelinnerdialog() {
      this.dialogTableVisible = false;
      this.dialogx = false;
    },
    popcomchange(c, v) {
      //"选择后code", c//"选择后name", v
      this.dialogx = false;
      if (this.dialogdata != "") {
        //如果是新增
        var myValue = " '" + c + "' ";
        this.InputCurrentPos(myValue);
      } else {
        //修改
        this.dialogdata += " '" + c + "' ";
      }
      this.dialogTableVisible = false;
    },
    PopListSearch() {
      let record = [];
      this.quicklysearch = this.quicklysearch.trim();
      if (this.quicklysearch != "") {
        record = this.poptempData.filter((item) => {
          return (item.col_table ? item.col_table.toUpperCase().indexOf(this.quicklysearch.toUpperCase()) > -1 : false) || (item.col_code ? item.col_code.indexOf(this.quicklysearch) > -1 : false) || (item.col_name ? item.col_name.toUpperCase().indexOf(this.quicklysearch.toUpperCase()) > -1 : false);
        });
      } else {
        record = XE.clone(this.poptempData, true);
      }
      this.poptableData = record;
    },
    TestSql() {
      this.$tool
        .request({
          url: "LIS/LIS1/LIS131",
          method: "post",
          data: {
            action: "TestSql",
            sql: this.dialogdata,
          },
        })
        .then((res) => {
          if (res.errcode == "1") {
            this.$alert("测试成功", "提示", { type: "success" });
          } else {
            this.$alert(res.errmsg, "提示", { type: "error" });
          }
        });
    },
    savedialog() {
      this.addParam.condsql = this.dialogdata;
      this.outerVisible = false;
      this.SaveAllRecord();
    },
    SelectColVal(code, name) {
      this.dialogx = false;
      this.dataclass = "LIS3_" + code;
      this.dialogtitle = "请选择" + name;
      this.dialogx = true;
      this.dialogTableVisible = true;
    },
    popcurrentChangeEvent({ row, column }) {
      //弹窗行选中事件
      if (column.property == "hasvaluelist") return;
      let sqlstr = "";
      switch (row.col_table) {
        case "报告表":
          sqlstr = " a." + row.col_code;
          break;
        case "申请表":
          if (this.dialogdata.indexOf(" exists (select 1 from req_master") > -1) {
            sqlstr = "req_master." + row.col_code;
          } else {
            sqlstr = " exists (select 1 from req_master (nolock) where req_master.barcode = a.barcode and req_master." + row.col_code + " )";
          }
          break;
        case "结果表":
          if (this.dialogdata.indexOf(" exists (select 1 from lab_result") > -1) {
            sqlstr = "lab_result." + row.col_code;
          } else {
            sqlstr = " exists (select 1 from lab_result (nolock) where lab_result.reportid = a.reportid and lab_result." + row.col_code + " )";
          }
          break;
      }
      this.InputCurrentPos(sqlstr);
    },
    //把插入的字段或值放到当前光标所在位置
    InputCurrentPos(myValue, table) {
      var myField = document.getElementById("topdiv");
      if (myField.selectionStart || myField.selectionStart === 0) {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        this.dialogdata = myField.value.substring(0, startPos) + " " + myValue + " " + myField.value.substring(endPos, myField.value.length);
        this.$nextTick(() => {
          myField.selectionStart = startPos + myValue.length + 2;
          myField.selectionEnd = startPos + myValue.length + 2;
        }); // 这句是重点, 圈起来
        myField.focus();
        myField.setSelectionRange(myField, myField.selectionStart, myField.selectionEnd);
      } else {
        this.dialogdata += " " + myValue + " ";
      }
    },
    operate(text) {
      //按钮选中
      let tempvarible = " " + text + " ";
      if (this.dialogdata != "") {
        this.InputCurrentPos(tempvarible);
      } else {
        this.dialogdata += tempvarible;
      }
    },
    SetIsAreaMode() {
      this.$tool
        .request({
          url: "LIS/LIS1/LIS131",
          method: "post",
          data: {
            action: "setIsAreaMode"
          }
        })
        .then(res => {
          this.IsAreaMode = res.IsAreaMode;
        });
    },
    CommitEndtime() {
      var workday_endtime = "";
      var weekend_endtime = "";
      var holiday_endtime = "";

      //把值拼成一个
      if (this.workday_endtime) {
        workday_endtime = this.workday_endtime;
      }
      if (this.weekend_endtime) {
        weekend_endtime = this.weekend_endtime;
      }
      if (this.holiday_endtime) {
        holiday_endtime = this.holiday_endtime;
      }
      var endtime = "工作日:" + workday_endtime + "|周末:" + weekend_endtime + "|节假日:" + holiday_endtime;


      if (endtime != "工作日:|周末:|节假日:") {
        if (this.rptunitendtimeuseflag) this.rptunitendtime = endtime;
        else this.endtime_row.endtime = endtime;
      } else {
        if (this.rptunitendtimeuseflag) this.rptunitendtime = "";
        else this.endtime_row.endtime = "";
      }

      this.endtimedialogForm = false;

      this.workday_endtime = "";
      this.weekend_endtime = "";
      this.holiday_endtime = "";
    },
    setendtime(code, row) {
      this.rptunitendtimeuseflag = false;
      this.endtime_row = row;
      this.endtime_code = code;

      var times = row.endtime;
      if (times && times.indexOf("|") > -1) {
        var timesArr = times.split("|");
        this.workday_endtime = timesArr[0].replace(/工作日:/, "");;
        this.weekend_endtime = timesArr[1].replace(/周末:/, "");
        this.holiday_endtime = timesArr[2].replace(/节假日:/, "");
      }

      this.endtimedialogForm = true;
    },
    setrptunitendtime() {
      this.rptunitendtimeuseflag = true;
      var times = this.rptunitendtime;
      if (times.indexOf("|") != -1) {
        var timesArr = times.split("|");
        this.workday_endtime = timesArr[0].replace(/工作日:/, "");;
        this.weekend_endtime = timesArr[1].replace(/周末:/, "");
        this.holiday_endtime = timesArr[2].replace(/节假日:/, "");
      }
      this.endtimedialogForm = true;
    },
    getButtonWidth() {
      if (this.$refs.buttondiv) {
        this.buttonwidth = this.$refs.buttondiv.offsetWidth + "px";
      }
    },
    currentChangeEvent({ row, rowIndex }) {
      this.LoadMdlDetail(row.inputmdlid);
      this.mdlid = row.inputmdlid;
    },
    currentChangeEventCon({ row, rowIndex }) {
      console.log(row);
      this.addParam = row;
    },
    InitOptions() {
      this.$tool
        .request({
          url: "LIS/LIS1/LIS131",
          method: "post",
          data: {
            action: "initOption"
          }
        })
        .then(res => {
          this.Options = res;
          //this.Options.rptunitvsallhospreqitem = "1";
        });
    },
    handleTabClick(tab, event) {
      this.TabLabel = tab.label;
      if (tab.label == "核收号段" || tab.label == "样本号跳转规则" || tab.label == "抗生素组" || tab.label == "申请科室" || tab.label == "列表过滤条件" || tab.label == "报告标记") this.buttonvisible = true;
      else this.buttonvisible = false;
      switch (tab.label) {
        case "输入模板":
          if (this.mdlFirst) {
            var row = {};
            this.LoadTable(2);
            this.$nextTick(() => {
              this.LoadMdlDetail(0);
              this.mdlFirst = false;
            });
          }
          break;
        case "申请项目":
          if (this.reqFirst) {
            this.LoadTable(3);
            this.LoadTable(12);
            this.$nextTick(() => {
              this.$refs.tablereq.insertAt({}, -1);
              var row = this.$refs.tablereq.tableData[this.$refs.tablereq.tableData.length - 1];
              this.$refs.tablereq.remove(row);
              this.reqFirst = false;
            });
          }
          break;
        case "标本类型":
          if (this.specFirst) {
            this.LoadTable(4);
            this.$nextTick(() => {
              this.specFirst = false;
            });
          }
          break;
        case "报告备注":
          if (this.commFirst) {
            this.LoadTable(5);
            this.$nextTick(() => {
              this.commFirst = false;
            });
          }
          break;
        case "核收号段":
          if (this.sampleFirst) {
            this.LoadTable(6);
            this.sampleFirst = false;
          }
          break;
        case "样本号跳转规则":
          if (this.smpgotoFirst) {
            this.LoadTable(7);
            this.smpgotoFirst = false;
          }
          break;
        case "抗生素组":
          if (this.medgroupFirst) {
            this.LoadTable(8);
            this.medgroupFirst = false;
          }
          break;
        case "申请科室":
          if (this.deptFirst) {
            this.LoadTable(9);
            this.deptFirst = false;
          }
          break;
        case "列表过滤条件":
          if (this.condFirst) {
            this.LoadTable(10);
            this.condFirst = false;
          }
          if (this.$refs.tableConditiond.getTableData().fullData.length > 0) {
            this.$refs.tableConditiond.setCurrentRow(this.$refs.tableConditiond.getTableData().fullData[0]);
            this.editaddParamflag = false;
          }
          break;
        case "报告标记":
          if (this.MarkFirst) {
            this.LoadTable(11);
            this.MarkFirst = false;
          }
          break;
      }
    },
    cellDBLClickEvent({ row, rowIndex, column, columnIndex }, event) {
      switch (this.TabLabel) {
        case "分单类别":
          this.UnitGroupTable(row);
          break;
        case "输入模板":
          this.UnitMdlTable(row);
          break;
        case "申请项目":
          this.UnitReqTable(row);
          break;
        case "标本类型":
          this.UnitSpecTable(row);
          break;
        case "报告备注":
          this.UnitCommTable(row);
          break;
        default:
          break;
      }
    },
    UnitGroupTable(row) {
      if (row.req_groupid != undefined) {
        if (row.Inuse == "0") {
          var len = this.$refs.tableGroupvs.getTableData().fullData.length + 1;
          var insertrow = {
            req_groupname: row.req_groupname,
            seq: len * 10,
            reg_groupid: row.req_groupid
          };
          this.$refs.tableGroupvs.insertAt(insertrow, -1);
          var delitem = this.tableDataGroup.filter(p => {
            return p.req_groupid == row.req_groupid;
          });
          var index = this.tableDataGroup.indexOf(delitem[0]);
          index > -1 && (this.tableDataGroup[index].Inuse = "1");
          this.tableDataGroup = this.tableDataGroup.sort((a, b) => a.req_groupid - b.req_groupid);
          this.tableDataGroup = this.tableDataGroup.sort((a, b) => a.Inuse - b.Inuse);
        }
      } else {
        var resetrow = this.tableDataGroup.filter(function (p) {
          return p.req_groupid === row.reg_groupid;
        });
        if (resetrow.length > 0) {
          var index = this.tableDataGroup.indexOf(resetrow[0]);
          this.tableDataGroup[index].Inuse = "0";
        }
        this.tableDataGroup = this.tableDataGroup.sort((a, b) => a.req_groupid - b.req_groupid);
        this.tableDataGroup = this.tableDataGroup.sort((a, b) => a.Inuse - b.Inuse);
        this.$refs.tableGroupvs.remove(row);
      }
    },
    UnitMdlTable(row) {
      if (row.inputcode != undefined) {
        this.mdlid = row.inputmdlid;
        this.DealMdl();
      } else {
        var resetrow = this.tableDataMdlTemp.filter(function (p) {
          return p.inputmdlid === row.inputmdlid;
        });
        if (resetrow.length > 0) {
          this.tableDataMdl.push(resetrow[0]);
          this.tableDataMdl = this.tableDataMdl.sort((a, b) => a.inputmdlid - b.inputmdlid);
        }
        this.$refs.tableUnitMdl.remove(row);
      }
    },
    UnitReqTable(row) {
      if (row.his_itemcode != undefined) {
        if (row.Inuse == "0") {
          var len = this.$refs.tableUnitreq.getTableData().fullData.length + 1;
          var insertrow = {
            req_item: row.req_itemname + " [" + row.req_itemcode + "]",
            req_itemcode: row.req_itemcode,
            defaultselect: "",
            inputcode: "",
            forbidinputflag: this.forbidflag,
            sampleno1: 0,
            sampleno2: 0,
            sampleformat: "",
            autonoruleid: 0,
            weekdays: "",
            endtime: "",
            specialreqitem: "",
            seq: len * 10,
            rptunitid: this.rptunit
          };
          this.$refs.tableUnitreq.insertAt(insertrow, -1);
          var delitem = this.tableDatareq.filter(p => {
            return p.req_itemcode == row.req_itemcode;
          });
          var index = this.tableDatareq.indexOf(delitem[0]);
          index > -1 && (this.tableDatareq[index].Inuse = "1");
          //this.tableDatareq = this.tableDatareq.sort((a, b) => a.Inuse - b.Inuse);
        }
      } else {
        if (!this.deltipflag) {
          this.dialogFormVisible = true;
        } else {
          this.UnitReqdblEvent();
        }
      }
    },
    UnitSpecTable(row) {
      if (row.inputcode != undefined) {
        if (row.Inuse == "0") {
          var len = this.$refs.tableUnitspec.getTableData().fullData.length + 1;
          var insertrow = {
            specimen_name: row.specimen_name,
            seq: len * 10,
            specimen_code: row.specimen_code
          };
          this.$refs.tableUnitspec.insertAt(insertrow, -1);
          var delitem = this.tableDataSpec.filter(p => {
            return p.specimen_code == row.specimen_code;
          });
          var index = this.tableDataSpec.indexOf(delitem[0]);
          index > -1 && (this.tableDataSpec[index].Inuse = "1");
          this.tableDataSpec = this.tableDataSpec.sort((a, b) => a.specimen_code.charCodeAt(0) - b.specimen_code.charCodeAt(0));
          this.tableDataSpec = this.tableDataSpec.sort((a, b) => a.specimen_code - b.specimen_code);
          this.tableDataSpec = this.tableDataSpec.sort((a, b) => a.Inuse - b.Inuse);
        }
      } else {
        var resetrow = this.tableDataSpec.filter(function (p) {
          return p.specimen_code === row.specimen_code;
        });
        if (resetrow.length > 0) {
          var index = this.tableDataSpec.indexOf(resetrow[0]);
          this.tableDataSpec[index].Inuse = "0";
          this.tableDataSpec = this.tableDataSpec.sort((a, b) => a.specimen_code.charCodeAt(0) - b.specimen_code.charCodeAt(0));
          this.tableDataSpec = this.tableDataSpec.sort((a, b) => a.specimen_code - b.specimen_code);
          this.tableDataSpec = this.tableDataSpec.sort((a, b) => a.Inuse - b.Inuse);
        }
        this.$refs.tableUnitspec.remove(row);
      }
    },
    UnitCommTable(row) {
      if (row.codeno != undefined) {
        if (row.Inuse == "0") {
          var len = this.$refs.tableUnitComm.getTableData().fullData.length + 1;
          var insertrow = {
            comments: row.codena,
            seq: len * 10,
            inputcode: row.inputcode
          };
          this.$refs.tableUnitComm.insertAt(insertrow, -1);
          var delitem = this.tableDataComm.filter(p => {
            return p.codena == row.codena;
          });
          var index = this.tableDataComm.indexOf(delitem[0]);
          index > -1 && (this.tableDataComm[index].Inuse = "1");
          this.tableDataComm = this.tableDataComm.sort((a, b) => a.codeno.charCodeAt(0) - b.codeno.charCodeAt(0));
          this.tableDataComm = this.tableDataComm.sort((a, b) => a.codeno - b.codeno);
          this.tableDataComm = this.tableDataComm.sort((a, b) => a.Inuse - b.Inuse);
        }
      } else {
        var resetrow = this.tableDataComm.filter(function (p) {
          return p.codena === row.comments;
        });
        if (resetrow.length > 0) {
          var index = this.tableDataComm.indexOf(resetrow[0]);
          this.tableDataComm[index].Inuse = "0";
          this.tableDataComm = this.tableDataComm.sort((a, b) => a.codeno.charCodeAt(0) - b.codeno.charCodeAt(0));
          this.tableDataComm = this.tableDataComm.sort((a, b) => a.codeno - b.codeno);
          this.tableDataComm = this.tableDataComm.sort((a, b) => a.Inuse - b.Inuse);
        }
        this.$refs.tableUnitComm.remove(row);
      }
    },
    UnitReqdblEvent() {
      var row = this.$refs.tableUnitreq.getCurrentRow();
      var resetrow = this.tableDatareq.filter(function (p) {
        return p.req_itemcode === row.req_itemcode;
      });
      if (resetrow.length > 0) {
        var index = this.tableDatareq.indexOf(resetrow[0]);
        this.tableDatareq[index].Inuse = "0";
        //this.tableDatareq = this.tableDatareq.sort((a, b) => a.Inuse - b.Inuse);
      }
      this.$refs.tableUnitreq.remove(row);
    },
    LoadTable(type) {
      this.loading = true;
      this.$tool
        .request({
          url: "LIS/LIS1/LIS131",
          method: "post",
          data: {
            action: "query",
            rptunitid: this.rptunit,
            datatype: type,
            hospcode: this.hospcode
          }
        })
        .then(res => {
          switch (type) {
            case 1:
              this.tableDataGroupvs = res.Data;
              break;
            case 2:
              var unitmdl = res.Data;
              for (let i = 0, len = unitmdl.length; i < len; i++) {
                var temp = unitmdl[i];
                unitmdl[i].autoinputflag = temp.autoinput > 0 ? true : false;
                unitmdl[i].mdlinvalidflag = temp.mdlinvalid > 0 ? true : false;
              }
              this.tableDataUnitMdl = unitmdl;
              break;
            case 3:
              var unitreq = res.Data;
              for (let i = 0, len = unitreq.length; i < len; i++) {
                var temp = unitreq[i];
                unitreq[i].req_item = temp.req_itemname + " " + "[" + temp.req_itemcode + "]";
                unitreq[i].forbidinputflag = temp.forbidinput > 0 ? true : false;
                unitreq[i].defaultselectflag = temp.defaultselect > 0 ? true : false;
                unitreq[i].specialreqitemflag = temp.specialreqitem > 0 ? true : false;
                if (temp.endtime) {
                  var tempendtime = temp.endtime.split("|");
                  if (tempendtime.length > 0 && tempendtime[0] != "") {
                    unitreq[i].endtime = "工作日:" + tempendtime[0] + "|周末:" + tempendtime[1] + "|节假日:" + tempendtime[2];
                  }
                  else {
                    unitreq[i].endtime = "";
                  }
                }

              }
              this.tableDataUnitreq = unitreq;
              this.LoadTableDict(6);
              break;
            case 4:
              this.tableDataUnitSpec = res.Data;
              break;
            case 5:
              this.tableDataUnitComm = res.Data;
              break;
            case 6:
              this.tableDataSample = res.Data;
              break;
            case 7:
              this.tableDataSmpGoto = res.Data;
              break;
            case 8:
              this.tableDataMedgroup = res.Data;
              break;
            case 9:
              this.tableDataDept = res.Data;
              break;
            case 10:
              this.tableDataCond = res.Data;
              this.$nextTick(() => {
                if (this.tableDataCond.length > 0) {
                  var row = this.tableDataCond.find(item => item.condname == this.addParam.condname);
                  if (row) {
                    this.$refs.tableConditiond.setCurrentRow(row);
                    this.addParam = row;
                  } else {
                    this.$refs.tableConditiond.setCurrentRow(this.tableDataCond[0]);
                    this.addParam = this.tableDataCond[0];
                  }
                  this.editaddParamflag = false;
                }
              });
              break;
            case 11:
              this.tableDataMark = res.Data;
            case 12:
              if (res.Data.length > 0) {
                this.rptunitweekdays = res.Data[0].weekdays;
                if (res.Data[0].endtime) {
                  var endtime = res.Data[0].endtime.split("|");
                  if (endtime.length > 0 && endtime[0] != "") {
                    this.rptunitendtime = "工作日:" + endtime[0] + "|周末:" + endtime[1] + "|节假日:" + endtime[2];
                  }
                }

                this.isnextorstop = res.Data[0].isnextorstop;
              }
              else {
                this.rptunitweekdays = "";
                this.rptunitendtime = "";
                this.isnextorstop = "0";
              }
          }
          this.loading = false;
          if (type <= 5) this.LoadTableDict(type);
        })
        .catch(error => {
          console.log(error);
        });
    },
    LoadTableDict(type) {
      this.loadingDict = true;
      this.$tool
        .request({
          url: "LIS/LIS1/LIS131",
          method: "post",
          data: {
            action: "querybasedata",
            rptunitid: this.rptunit,
            datatype: type,
            hospcode: this.hospcode
          }
        })
        .then(res => {
          switch (type) {
            case 1:
              this.tableDataGroup = this.DealDataInuse(res.Data, this.tableDataGroupvs, "group");
              this.tableDataGroup = this.tableDataGroup.sort((a, b) => a.Inuse - b.Inuse);
              break;
            case 2:
              this.tableDataMdl = res.Data;
              break;
            case 3:
              //var reqdata = this.DealDataInuse(res.Data, this.tableDataUnitreq, "req");
              //reqdata = reqdata.sort((a, b) => a.req_itemname.charCodeAt(0) - b.req_itemname.charCodeAt(0));
              //reqdata = reqdata.sort((a, b) => a.Inuse - b.Inuse);
              this.tableDatareq = res.Data;
              this.tableDatareqTemp = res.Data;
              this.getreqTempData(this.reqgroup);
              break;
            case 4:
              this.tableDataSpec = this.DealDataInuse(res.Data, this.tableDataUnitSpec, "spec");
              this.tableDataSpec = this.tableDataSpec.sort((a, b) => a.Inuse - b.Inuse);
              break;
            case 5:
              this.tableDataComm = this.DealDataInuse(res.Data, this.tableDataUnitComm, "comm");
              this.tableDataComm = this.tableDataComm.sort((a, b) => a.Inuse - b.Inuse);
              break;
            case 6:
              this.OptionsAutorule = res.Data;
              break;
          }

          this.loadingDict = false;
        })
        .catch(e => {
          console.log(e);
        });
    },
    LoadMdlDetail(id) {
      this.loadingDict = true;
      this.$tool
        .request({
          url: "LIS/LIS1/LIS131",
          method: "post",
          data: {
            action: "inputmdldetail",
            inputmdlid: id
          }
        })
        .then(res => {
          this.tableDataContain = res.Data;
          this.tableColumnCotain = res.Cols;
          this.loadingDict = false;
        });
    },
    DealMdl() {
      this.$tool
        .request({
          url: "LIS/LIS1/LIS131",
          method: "post",
          data: {
            action: "checkinputmdlitem",
            inputmdlid: this.mdlid,
            rptunitid: this.rptunit
          }
        })
        .then(res => {
          if (res) {
            this.mdlunititem = res;
            this.dialogmdlVisible = true;
          } else {
            this.UnitmdlAdd();
          }
        });
    },
    UnitmdlAdd() {
      var row = this.$refs.tableMdl.getCurrentRow();
      var hasrow = this.$refs.tableUnitMdl.tableData.filter(item => {
        return item.inputmdlid == row.inputmdlid;
      });
      if (hasrow.length == 0) {
        var len = this.$refs.tableUnitMdl.getTableData().fullData.length + 1;
        var insertrow = {
          mdlname: row.mdlname,
          autoinputflag: false,
          sampleno1: 0,
          sampleno2: 0,
          hotkey: "",
          seq: len * 10,
          mdlspecimenname: row.specimen_name,
          mdlinvalidflag: row.invalid > 0,
          inputmdlid: row.inputmdlid
        };
        this.$refs.tableUnitMdl.insertAt(insertrow, -1);
      }
    },
    UnitmdlReqAdd() {
      this.$tool
        .request({
          url: "LIS/LIS1/LIS131",
          method: "post",
          data: {
            action: "autoaddrptunititem",
            inputmdlid: this.mdlid,
            rptunitid: this.rptunit
          }
        })
        .then(res => {
          if (res.errcode == 1) {
            this.$message({
              message: "对照成功",
              type: "success"
            });
          } else {
            this.$message.error("对照失败:" + res.errmsg);
          }
        });
    },
    SaveAllRecord() {
      var record1 = this.$refs.tableGroupvs.tableData;
      this.SetAllseq(record1);
      var record2 = this.$refs.tableUnitMdl.tableData;
      this.SetAllseq(record2);
      var record3 = this.$refs.tableUnitreq.tableData;
      // this.SetAllseq(record3);
      var record4 = this.$refs.tableUnitspec.tableData;
      this.SetAllseq(record4);
      var record5 = this.$refs.tableUnitComm.tableData;
      this.SetAllseq(record5);
      var record9 = this.$refs.tableDept.tableData;
      this.SetAllseq(record9);
      var grouprecord = this.$refs.tableGroupvs.getRecordset();
      var mdlrecord = this.$refs.tableUnitMdl.getRecordset();
      var reqrecord = this.$refs.tableUnitreq.getRecordset();
      var specrecord = this.$refs.tableUnitspec.getRecordset();
      var commrecord = this.$refs.tableUnitComm.getRecordset();
      var samplerecord = this.$refs.tableSample.getRecordset();
      var smpgotorecord = this.$refs.tableSmpgoto.getRecordset();
      var medrecord = this.isbis ? null : this.$refs.tableMedgroup.getRecordset();
      var deptrecord = this.$refs.tableDept.getRecordset();
      var condrecord = this.$refs.tableConditiond.getRecordset();
      var markrecord = this.$refs.tableMark.getRecordset();
      var returngrouprecord = this.GetReturnRecord(grouprecord, "group");
      var returnmdlrecord = this.GetReturnRecord(mdlrecord, "mdl");
      var returnreqrecord = this.GetReturnRecord(reqrecord, "req");
      var returnspecrecord = this.GetReturnRecord(specrecord, "spec");
      var returncommrecord = this.GetReturnRecord(commrecord, "comm");
      var returnsamplerecord = this.GetReturnRecord(samplerecord, "sample");
      var returnsmpgotorecord = this.GetReturnRecord(smpgotorecord, "smpgoto");
      var returnmedrecord = this.isbis ? null : this.GetReturnRecord(medrecord, "medgroup");
      var rptunitendtime = this.rptunitendtime;
      if (rptunitendtime) {
        rptunitendtime = rptunitendtime.replace(/工作日:/, "");
        rptunitendtime = rptunitendtime.replace(/周末:/, "");
        rptunitendtime = rptunitendtime.replace(/节假日:/, "");
      }
      //var returndeptrecord = this.GetReturnRecord(deptrecord, "dept");
      //console.log(returndeptrecord);
      this.$tool
        .request({
          url: "LIS/LIS1/LIS131",
          method: "post",
          data: {
            action: "save",
            rptunitid: this.rptunit,
            urec1: returngrouprecord,
            urec2: returnmdlrecord,
            urec3: returnreqrecord,
            urec4: returnspecrecord,
            urec5: returncommrecord,
            urec6: returnsamplerecord,
            urec7: returnsmpgotorecord,
            urec8: returnmedrecord,
            urec9: deptrecord,
            urec10: condrecord,
            urec11: markrecord,
            rptunitweekdays: this.rptunitweekdays,
            rptunitendtime: rptunitendtime,
            isnextorstop: this.isnextorstop,
          }
        })
        .then(res => {
          if (res.errcode == 1) {
            this.$message({
              message: "保存成功",
              type: "success"
            });
            this.LoadAll();
          } else {
            this.$message.error("保存失败:" + res.errmsg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    unitchange(code, name) {
      this.rptunit = code;
      this.LoadAll();
    },
    reqgroupchange(code, name) {
      this.reqgroup = code;
      this.getreqTempData(this.reqgroup);
    },

    getreqTempData(reqgroupid) {
      let totaldata = XE.clone(this.tableDatareqTemp, true);
      if (reqgroupid) {
        this.tableDatareq = totaldata.filter(item => {
          return item.req_groupid == reqgroupid;
        });
      } else this.tableDatareq = totaldata;
    },

    smp_specimenchange(code, row) {
      //row.specimencode = code;
    },
    pat_typechange(code, row) {
      row.pat_typecode = code;
    },
    medgroupchange(code, row) {
      row.medgroupcode = code;
    },
    deptchange(code, row) {
      row.req_deptno = code;
    },
    DealDataInuse(data, smallarr, key) {
      for (let i = 0, len = data.length; i < len; i++) {
        data[i].Inuse = "0";
      }
      var redata = this.CheckArrHas(data, smallarr, key);
      return redata;
    },
    CheckArrHas(Bigarr, smallarr, key) {
      if (smallarr) {
        for (let i = 0, len = smallarr.length; i < len; i++) {
          var resetrow = [];
          switch (key) {
            case "group":
              resetrow = Bigarr.filter(function (p) {
                return p.req_groupid === smallarr[i].reg_groupid;
              });
              break;
            case "spec":
              resetrow = Bigarr.filter(function (p) {
                return p.specimen_code === smallarr[i].specimen_code;
              });
              break;
            case "req":
              resetrow = Bigarr.filter(function (p) {
                return p.req_itemcode === smallarr[i].req_itemcode;
              });
              break;
            case "comm":
              resetrow = Bigarr.filter(function (p) {
                return p.codena === smallarr[i].comments;
              });
              break;
          }

          var index = Bigarr.indexOf(resetrow[0]);
          if (index > -1) Bigarr[index].Inuse = "1";
        }
      }

      return Bigarr;
    },
    AddRecord() {
      switch (this.TabLabel) {
        case "核收号段":
          var newrow = {};
          this.AddDeal(this.$refs.tableSample, newrow, "seq");
          break;
        case "样本号跳转规则":
          var newrow = {};
          this.AddDeal(this.$refs.tableSmpgoto, newrow, "currsmpno");
          break;
        case "抗生素组":
          var newrow = { rptunitid: this.rptunit };
          this.AddDeal(this.$refs.tableMedgroup, newrow, "med");
          break;
        case "申请科室":
          var len = this.$refs.tableDept.getTableData().fullData.length + 1;
          var newrow = { seq: len * 10 };
          this.AddDeal(this.$refs.tableDept, newrow, "dept");
          break;
        case "列表过滤条件":
          var len = this.$refs.tableConditiond.getTableData().fullData.length + 1;
          var newrow = { rptunitid: this.rptunit, seq: len * 10, condname: "", condsql: "", useflag: "0" };
          this.AddDeal(this.$refs.tableConditiond, newrow, "cond");
          break;
        case "报告标记":
          var len = this.$refs.tableMark.getTableData().fullData.length + 1;
          var newrow = { rptunitid: this.rptunit, seq: len * 10, markname: "", markno: "" };
          this.AddDeal(this.$refs.tableMark, newrow, "mark");
          break;
      }
    },
    DelRecord() {
      switch (this.TabLabel) {
        case "核收号段":
          this.DelDeal(this.$refs.tableSample);
          break;
        case "样本号跳转规则":
          this.DelDeal(this.$refs.tableSmpgoto);
          break;
        case "抗生素组":
          this.DelDeal(this.$refs.tableMedgroup);
          break;
        case "申请科室":
          this.DelDeal(this.$refs.tableDept);
          break;
        case "列表过滤条件":
          this.deleteCondition();
          // this.DelDeal(this.$refs.tableConditiond);
          break;
        case "报告标记":
          this.DelDeal(this.$refs.tableMark);
          break;
      }
    },
    GetReturnRecord(records, tabletype) {
      var exactArr = { insertRecords: [], removeRecords: [], updateRecords: [] };
      if (records.insertRecords.length > 0) {
        exactArr.insertRecords = this.GetoneRecords(records.insertRecords, 1, tabletype);
      }
      if (records.removeRecords.length > 0) {
        exactArr.removeRecords = this.GetoneRecords(records.removeRecords, 3, tabletype);
      }
      if (records.updateRecords.length > 0) {
        exactArr.updateRecords = this.GetoneRecords(records.updateRecords, 2, tabletype);
      }
      return exactArr;
    },
    GetoneRecords(records, type, tabletype) {
      var recordsarr = [];
      for (let i = 0, len = records.length; i < len; i++) {
        if (type != 2) {
          var onerecord = this.GetOneRecord(records[i], tabletype);
          switch (tabletype) {
            case "sample":
              if (onerecord.segname && onerecord.startno && onerecord.endno) recordsarr.push(onerecord);
              break;
            case "smpgoto":
              if (onerecord.currsmpno && onerecord.nextsmpno) recordsarr.push(onerecord);
              break;
            case "medgroup":
              if (onerecord.medgroupcode) recordsarr.push(onerecord);
              break;
            case "dept":
              break;
              break;
            default:
              recordsarr.push(onerecord);
              break;
          }
        } else {
          var onerecord = { odata: {}, cdata: {} };
          console.info(records[i]);
          onerecord.odata = this.GetOneRecord(records[i].odata, tabletype);
          onerecord.cdata = this.GetOneRecord(records[i].cdata, tabletype);
          recordsarr.push(onerecord);
        }
      }
      return recordsarr;
    },
    GetOneRecord(record, tabletype) {
      var returnrecord = {};
      switch (tabletype) {
        case "group":
          returnrecord = {
            reg_groupid: record.reg_groupid,
            seq: record.seq
          };
          break;
        case "mdl":
          returnrecord = {
            inputmdlid: record.inputmdlid,
            autoinput: record.autoinputflag ? 1 : 0,
            sampleno1: record.sampleno1,
            sampleno2: record.sampleno2,
            hotkey: record.hotkey,
            seq: record.seq
          };
          break;
        case "req":
          returnrecord = {
            req_itemcode: record.req_itemcode,
            defaultselect: record.defaultselectflag ? 1 : 0,
            inputcode: record.inputcode,
            forbidinput: record.forbidinputflag ? 1 : 0,
            sampleno1: record.sampleno1,
            sampleno2: record.sampleno2,
            sampleformat: record.sampleformat,
            autonoruleid: record.autonoruleid,
            weekdays: record.weekdays,
            endtime: record.endtime,
            specialreqitem: record.specialreqitemflag ? 1 : 0,
            seq: record.seq
          };
          break;
        case "spec":
          returnrecord = {
            specimen_code: record.specimen_code,
            seq: record.seq
          };
          break;
        case "comm":
          returnrecord = {
            comments: record.comments,
            seq: record.seq,
            inputcode: record.inputcode
          };
          break;
        case "sample":
          if (record.segname && record.startno && record.endno)
            returnrecord = {
              seq: record.seq,
              endno: record.endno,
              pat_typecode: record.pat_typecode,
              segname: record.segname,
              specimencode: record.specimencode,
              startno: record.startno
            };
          else returnrecord = {};
          break;
        case "smpgoto":
          returnrecord = record;
          break;
        case "medgroup":
          if (record.medgroupcode)
            returnrecord = {
              medgroupcode: record.medgroupcode
            };
          else returnrecord = {};
          break;
        case "dept":
          returnrecord = {
            req_deptno: record.req_deptno,
            seq: record.seq
          };
          break;
      }
      return returnrecord;
    },
    ColorChange(color) {
      var tempcolor = color.toString(16);
      var num = 6 - tempcolor.length;
      var result = tempcolor;
      if (num > 0) {
        for (let i = 0; i < num; i++) {
          result = "0" + result;
        }
      }
      var resultarr = result.split("");
      var r1 = resultarr[0];
      var r2 = resultarr[1];
      resultarr[0] = resultarr[4];
      resultarr[1] = resultarr[5];
      resultarr[4] = r1;
      resultarr[5] = r2;
      result = resultarr.join("");
      return result;
    },
    SetAllseq(record) {
      for (let i = 0, len = record.length; i < len; i++) {
        record[i].seq = (i + 1) * 10;
      }
    },
    SeqClose(a) {
      if (a.column.title == "序号") {
        this.seqChangeflag = true;
        //var record = this.$refs.tableUnitreq.tableData;
        var record = a.$table.tableData;
        record = record.sort((a, b) => a.seq - b.seq);
      }
    },
    LoadAll() {
      var index1 = 0;
      var index2 = 0;
      var index3 = 0;
      var index4 = 0;
      var index5 = 0;
      if (this.$refs.tableGroupvs.getCurrentRow()) {
        index1 = this.$refs.tableGroupvs.getRowIndex(this.$refs.tableGroupvs.getCurrentRow());
      }
      this.LoadTable(1);
      this.RedictRow(this.$refs.tableGroupvs, index1);
      if (!this.mdlFirst) {
        if (this.$refs.tableUnitMdl.getCurrentRow()) {
          index2 = this.$refs.tableUnitMdl.getRowIndex(this.$refs.tableUnitMdl.getCurrentRow());
        }
        this.LoadTable(2);
        this.RedictRow(this.$refs.tableUnitMdl, index2);
        this.$nextTick(() => {
          this.LoadMdlDetail(0);
        });
      }
      if (!this.reqFirst) {
        if (this.$refs.tableUnitreq.getCurrentRow()) {
          index3 = this.$refs.tableUnitreq.getRowIndex(this.$refs.tableUnitreq.getCurrentRow());
        }
        this.LoadTable(3);
        this.LoadTable(12);
        this.RedictRow(this.$refs.tableUnitreq, index3);
      }
      if (!this.specFirst) {
        if (this.$refs.tableUnitspec.getCurrentRow()) {
          index4 = this.$refs.tableUnitspec.getRowIndex(this.$refs.tableUnitspec.getCurrentRow());
        }
        this.LoadTable(4);
        this.RedictRow(this.$refs.tableUnitspec, index4);
      }
      if (!this.commFirst) {
        if (this.$refs.tableUnitComm.getCurrentRow()) {
          index5 = this.$refs.tableUnitComm.getRowIndex(this.$refs.tableUnitComm.getCurrentRow());
        }
        this.LoadTable(5);
        this.RedictRow(this.$refs.tableUnitComm, index5);
      }
      if (!this.sampleFirst) {
        this.LoadTable(6);
      }

      if (!this.smpgotoFirst) {
        this.LoadTable(7);
      }

      if (!this.medgroupFirst) {
        this.LoadTable(8);
      }

      if (!this.deptFirst) {
        this.LoadTable(9);
      }
      if (!this.condFirst) {
        this.LoadTable(10);
      }
      if (!this.MarkFirst) {
        this.LoadTable(11);
      }
    },
    DelDeal(table) {
      var delrow = table.getCurrentRow();
      if (this.DelIndex < 0) this.DelIndex = table.getRowIndex(delrow);
      table.remove(delrow);
      if (this.DelIndex > -1 && table.tableData.length > 0) {
        if (table.getTableData().fullData.length > this.DelIndex) this.DelIndex = this.DelIndex;
        else this.DelIndex = this.DelIndex - 1;
        var selectrow = table.getTableData().fullData[this.DelIndex];

        this.$nextTick(() => {
          table.setCurrentRow(selectrow);
          var nownum = this.DelIndex * 2;
          table.$refs.tableBody.$children[nownum].$refs.ddlrptitemSelect.focus();
        });
      } else {
        var nowdata = table.getTableData().fullData.filter(item => {
          return item._XID < delrow._XID;
        });
        if (nowdata.length > 0) {
          var selectrow = nowdata[nowdata.length - 1];
          this.$nextTick(() => {
            table.setCurrentRow(selectrow);
            var nownum = (nowdata.length - 1) * 2;
          });
        }
      }
    },
    AddDeal(table, row, column) {
      table.insertAt(row, -1);
      var curow = table.getTableData().fullData[table.getTableData().fullData.length - 1];
      table.setCurrentRow(curow);
      if (column == "cond") {
        table.setActiveCell(curow, column);
        this.addParam = this.$refs.tableConditiond.getCurrentRow();
        this.editaddParamflag = false;
        this.$refs.input1.select();
      } else if (column != "med" && column != "dept") {
        table.setActiveCell(curow, column);
      } else {
        this.$nextTick(() => {
          var nownum = table.$refs.tableBody.$children.length - 1;
          table.$refs.tableBody.$children[nownum].$refs.ddlmainSelect.focus();
        });
      }
    },
    RedictRow(table, tempindex) {
      var selectrow = {};
      if (tempindex < table.tableData.length) selectrow = table.getData(tempindex);
      else selectrow = table.getData(table.tableData.length - 1);
      if (selectrow) {
        this.$nextTick(() => {
          table.setCurrentRow(selectrow);
          table.scrollToRow(selectrow);
        });
      }
    },
    hospChange(c, n) {
      this.LoadTableDict(3);
    },
    //报告标记代码更改
    MarkChange(args, prow) {
      if (this.$refs.tableMark.getTableData().fullData.filter(item => item.markno == args[0]).length > 1) {
        this.$alert("该报告单元对应标记代码已存在!", "提示");
        prow.markno = "";
      } else {
        prow.markname = args[1];
      }
    },
    // 回车切换输入框
    nextFocus(index) {
      if (index > 3) return false;
      var that = this;
      var focusIndex = index + 1;
      setTimeout(function () {
        that.$refs["input" + focusIndex].focus();
      }, 1);
    },
    deleteCondition() {
      var that = this;
      that.$confirm("确定删除这条记录?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        // 删除不刷新表格
        var delrow = this.$refs.tableConditiond.getCurrentRow();
        var havedata = this.$refs.tableConditiond.getTableData().fullData;
        var rowindex = havedata.indexOf(delrow);
        this.$refs.tableConditiond.remove(delrow);
        if (havedata.length > 0) {
          if (rowindex >= havedata.length - 1) rowindex = rowindex - 1;
          let selectrow = this.$refs.tableConditiond.getTableData().fullData[rowindex];
          if (selectrow) {
            this.$refs.tableConditiond.setCurrentRow(selectrow);
            this.addParam = selectrow;
          } else {
            // this.$refs.tableConditiond.setCurrentRow(this.$refs.tableConditiond.getTableData().fullData[rowindex - 1]);
            // this.addParam = this.$refs.tableConditiond.getTableData().fullData[rowindex - 1];
            this.addParam = {};
            this.editaddParamflag = true;
          }
        } else {
          this.addParam = {};
          this.editaddParamflag = true;
        }
      });
    }
  }
};
</script>

<style scoped>
/deep/.el-input.is-disabled .el-input__inner {
  color: black;
}

/deep/.el-checkbox.is-disabled .el-checkbox__label {
  color: black;
}

/deep/.el-textarea.is-disabled .el-textarea__inner {
  color: black;
}

/deep/.vxe-input--wrapper .vxe-input {
  height: auto;
}

.pagetop {
  left: 0;
  right: 0;
  height: 36px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 5px;
}

.middle-left {
  position: absolute;
  height: 100%;
  width: 400px;
  left: 0px;
  top: 0;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 405px;
  right: 0;
  top: 0;
}

table tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
}

table tr td:nth-child(even) {
  text-align: left;
}

table tr td:nth-child(1) {
  width: 80px;
}

table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}

/deep/.el-checkbox__inner::after {
  border: 2px solid #000000 !important;
  box-sizing: content-box;
  content: "";
  border-left: 0 !important;
  border-top: 0 !important;
  height: 7px;
  left: 4px;
  position: absolute;
  top: 1px;
  transform: rotate(45deg) scaleY(0);
  width: 3px;
  transition: transform 0.15s ease-in 0.05s;
  transform-origin: center;
}

/deep/.el-checkbox__input.is-disabled+span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}

/deep/ .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner+.el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}

.cond-content {
  width: 100%;
  height: 100%;
  display: flex;
}

/deep/ .cond-content .vxe-table {
  height: 100%;
  width: 100%;
}

.cond-table {
  /*width: calc(100% - 455px);*/
  /* margin-right: 5px;*/
  width: 100%;
  height: 100%;
}

.cond-edit {
  /*width: 450px;*/
  height: 100%;
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
  border: solid 1px #cccccc;
}

.edit-row {
  display: flex;
  line-height: 26px;
  margin-top: 5px;
}

.edit-row-title {
  width: 80px;
  margin-right: 5px;
  text-align: right;
}

.edit-row-text {
  width: 100%;
}

/deep/ .sql-text .el-textarea__inner {
  padding: 5px !important;
  height: 350px;
}</style>
